#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# http://www.lmaye.com/
import socket

serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM);
print("create socket ...");
# host = socket.gethostname();
host = "127.0.0.1";
port = 8888;
# 绑定端口
serverSocket.bind((host, port));
# 设置最大连接数，超过后排队
serverSocket.listen(10);
while True:
    # 建立客户端连接
    clientsocket, addr = serverSocket.accept();
    print("连接地址：%s" % str(addr));
    msg = "server say: hello, welcome";
    clientsocket.sendall(msg.encode("UTF-8"));
    print("push: %s" % msg);
    rs = clientsocket.recv(1024);
    print("receive: %s" % rs);
    clientsocket.close();
